package com.venueproject.service.impl;

import com.venueproject.mapper.AppoimentMapper;
import com.venueproject.pojo.Appoiment;
import com.venueproject.pojo.PageBean;
import com.venueproject.pojo.Venue;
import com.venueproject.service.AppoimentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;

@Service
public class AppoimentServiceImpl implements AppoimentService {


    @Autowired
    private AppoimentMapper appoimentMapper;

    /**
     * 查询可预约场地
     * @param page
     * @param pageSize
     * @param number
     * @param name
     * @return
     */
    public PageBean page(Integer page, Integer pageSize, String number, String name) {
        //1.获取总记录数
        Long count = appoimentMapper.count(number,name);

        //2.获取分页查询结果列表
        Integer start = (page - 1) * pageSize;
        List<Venue> venueList = appoimentMapper.page(start,pageSize,number,name);

        //3.封装PageBean对象
        PageBean pageBean = new PageBean(count,venueList);
        return pageBean;
    }

    /**
     * 获取预约信息
     * @return
     */
    public List<Appoiment> getAppoiment() {
        return appoimentMapper.getAppoiment();
    }

    /**
     * 判断场地当日是否预约
     * @return
     */
    public Appoiment selectAppoiment(String number) {
        LocalDate dateTime = LocalDate.now();
        return appoimentMapper.selectAppoiment(number,dateTime);
    }

    /**
     * 插入预约信息
     * @param appoiment
     */
    public void insertAppoiment(Appoiment appoiment) {
        appoiment.setDate(LocalDate.now());
        appoimentMapper.insertAppoiment(appoiment);
    }

    /**
     * 预约人数加1
     * @param id
     */
    public void Addappoiment(int id) {
        appoimentMapper.Addappoiment(id);
    }
}
